```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>二叉树层序遍历算法详解</title>
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
        }
        .code-block {
            background-color: #1e293b;
            border-radius: 0.5rem;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .mermaid-container {
            background-color: white;
            border-radius: 0.5rem;
            padding: 2rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body class="min-h-screen">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="container mx-auto max-w-4xl">
            <div class="flex flex-col items-center text-center">
                <span class="text-purple-200 text-lg font-medium mb-4 flex items-center">
                    <i class="fas fa-code-branch mr-2"></i>算法精解系列
                </span>
                <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">二叉树层序遍历算法</h1>
                <p class="text-xl text-purple-100 max-w-2xl leading-relaxed">
                    深入解析BFS算法在二叉树遍历中的应用，掌握高效处理层级数据的核心技巧
                </p>
                <div class="mt-10 flex space-x-4">
                    <button class="bg-white text-purple-600 font-semibold px-6 py-3 rounded-lg hover:bg-purple-50 transition duration-300 flex items-center">
                        <i class="fas fa-play-circle mr-2"></i> 观看视频讲解
                    </button>
                    <button class="border-2 border-white text-white font-semibold px-6 py-3 rounded-lg hover:bg-white hover:text-purple-600 transition duration-300 flex items-center">
                        <i class="fas fa-book-reader mr-2"></i> 阅读更多算法
                    </button>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-6xl px-6 py-16">
        <!-- Problem Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-10 bg-purple-500 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">问题描述</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-10 items-start">
                <div>
                    <p class="text-lg text-gray-700 leading-relaxed mb-6">
                        给定一个二叉树，返回其按层序遍历得到的节点值（即逐层地，从左到右访问所有节点）。例如，给定二叉树 <code class="bg-gray-100 px-2 py-1 rounded">[3,9,20,null,null,15,7]</code>，返回其层序遍历结果为 <code class="bg-gray-100 px-2 py-1 rounded">[[3], [9,20], [15,7]]</code>。
                    </p>
                    
                    <div class="bg-gray-50 p-6 rounded-xl border border-gray-200 mb-6">
                        <h3 class="font-semibold text-lg text-gray-800 mb-3 flex items-center">
                            <i class="fas fa-lightbulb text-yellow-500 mr-2"></i> 理解题目
                        </h3>
                        <p class="text-gray-600">
                            层序遍历又叫广度优先遍历(BFS)，它从树的根节点开始，依次访问每一层的所有节点，然后再访问下一层的节点。这种遍历方式需要借助队列这种数据结构来实现。
                        </p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                    <div class="bg-purple-600 text-white px-4 py-3 flex items-center">
                        <i class="fas fa-project-diagram mr-2"></i>
                        <span class="font-medium">示例二叉树</span>
                    </div>
                    <div class="p-6">
                        <div class="mermaid-container">
                            <div class="mermaid">
                                graph TD
                                    A[3] --> B[9]
                                    A --> C[20]
                                    C --> D[15]
                                    C --> E[7]
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        
        <!-- Solution Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-10 bg-purple-500 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">解题思路与算法分析</h2>
            </div>
            
            <div class="grid md:grid-cols-3 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="text-purple-500 text-2xl mb-4">
                        <i class="fas fa-sitemap"></i>
                    </div>
                    <h3 class="font-bold text-xl text-gray-800 mb-3">BFS算法</h3>
                    <p class="text-gray-600">
                        广度优先搜索(Breadth-First Search)是解决层序遍历的核心算法，它通过队列实现节点的层级访问。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="text-purple-500 text-2xl mb-4">
                        <i class="fas fa-layer-group"></i>
                    </div>
                    <h3 class="font-bold text-xl text-gray-800 mb-3">队列的应用</h3>
                    <p class="text-gray-600">
                        使用队列存储当前层节点，处理完当前层后，将下一层节点加入队列，实现层级遍历。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="text-purple-500 text-2xl mb-4">
                        <i class="fas fa-stopwatch"></i>
                    </div>
                    <h3 class="font-bold text-xl text-gray-800 mb-3">时间复杂度</h3>
                    <p class="text-gray-600">
                        时间复杂度为O(n)，空间复杂度为O(w)，其中w是树的最大宽度。
                    </p>
                </div>
            </div>
            
            <div class="bg-gray-50 p-6 rounded-xl border border-gray-200 mb-8">
                <h3 class="font-semibold text-lg text-gray-800 mb-3 flex items-center">
                    <i class="fas fa-list-ol text-purple-500 mr-2"></i> 算法步骤详解
                </h3>
                <ol class="list-decimal list-inside space-y-3 text-gray-700">
                    <li class="pl-2">创建一个空的结果列表和一个队列</li>
                    <li class="pl-2">将根节点加入队列</li>
                    <li class="pl-2">当队列不为空时循环：
                        <ul class="list-disc list-inside ml-6 mt-1 space-y-1 text-gray-600">
                            <li>记录当前队列长度(当前层的节点数)</li>
                            <li>创建一个临时列表存储当前层节点值</li>
                            <li>循环处理当前层每个节点：出队、记录值、子节点入队</li>
                            <li>将当前层节点值列表加入结果</li>
                        </ul>
                    </li>
                    <li class="pl-2">返回最终结果</li>
                </ol>
            </div>
            
            <div class="mermaid-container mb-12">
                <div class="mermaid">
                    flowchart TD
                        A[开始] --> B[初始化结果列表和队列]
                        B --> C{队列是否为空?}
                        C -->|是| D[返回结果]
                        C -->|否| E[记录当前层节点数]
                        E --> F[初始化当前层列表]
                        F --> G[循环处理当前层节点]
                        G --> H[出队节点]
                        H --> I[记录节点值]
                        I --> J[子节点入队]
                        J --> K{当前层处理完成?}
                        K -->|否| G
                        K -->|是| L[当前层结果加入总结果]
                        L --> C
                </div>
            </div>
        </section>
        
        <!-- Code Section -->
        <section>
            <div class="flex items-center mb-8">
                <div class="w-2 h-10 bg-purple-500 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">实现代码</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <div class="bg-gray-800 rounded-t-xl p-4 flex items-center">
                        <div class="flex space-x-2 mr-4">
                            <span class="w-3 h-3 rounded-full bg-red-500"></span>
                            <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                            <span class="w-3 h-3 rounded-full bg-green-500"></span>
                        </div>
                        <span class="text-gray-300 font-mono">TreeNode.java</span>
                    </div>
                    <div class="code-block p-6 rounded-b-xl">
                        <pre class="text-gray-200 font-mono text-sm overflow-x-auto">
<code>/**
 * 二叉树节点定义
 */
public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}</code></pre>
                    </div>
                </div>
                
                <div>
                    <div class="bg-gray-800 rounded-t-xl p-4 flex items-center">
                        <div class="flex space-x-2 mr-4">
                            <span class="w-3 h-3 rounded-full bg-red-500"></span>
                            <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                            <span class="w-3 h-3 rounded-full bg-green-500"></span>
                        </div>
                        <span class="text-gray-300 font-mono">Solution.java</span>
                    </div>
                    <div class="code-block p-6 rounded-b-xl">
                        <pre class="text-gray-200 font-mono text-sm overflow-x-auto">
<code>public List&lt;List&lt;Integer&gt;&gt; levelOrder(TreeNode root) {
    // 存储层序遍历结果的列表
    List&lt;List&lt;Integer&gt;&gt; result = new ArrayList&lt;&gt;();
    
    // 如果根节点为空，直接返回空列表
    if (root == null) {
        return result;
    }
    
    // 使用队列进行广度优先搜索
    Queue&lt;TreeNode&gt; queue = new LinkedList&lt;&gt;();
    queue.offer(root); // 将根节点入队
    
    // 当队列不为空时，继续遍历
    while (!queue.isEmpty()) {
        // 当前层的节点数量
        int levelSize = queue.size();
        
        // 存储当前层的节点值
        List&lt;Integer&gt; currentLevel = new ArrayList&lt;&gt;();
        
        // 处理当前层的所有节点
        for (int i = 0; i &lt; levelSize; i++) {
            // 取出队首节点
            TreeNode node = queue.poll();
            
            // 将当前节点的值添加到当前层列表
            currentLevel.add(node.val);
            
            // 如果左子节点不为空，将其加入队列
            if (node.left != null) {
                queue.offer(node.left);
            }
            
            // 如果右子节点不为空，将其加入队列
            if (node.right != null) {
                queue.offer(node.right);
            }
        }
        
        // 将当前层的节点值列表添加到结果中
        result.add(currentLevel);
    }
    
    // 返回层序遍历的结果
    return result;
}</code></pre>
                    </div>
                </div>
            </div>
            
            <div class="mt-8 bg-blue-50 border border-blue-200 rounded-xl p-6">
                <h3 class="font-semibold text-lg text-blue-800 mb-3 flex items-center">
                    <i class="fas fa-question-circle text-blue-500 mr-2"></i> 代码解析
                </h3>
                <ul class="list-disc list-inside space-y-2 text-blue-700">
                    <li><span class="font-medium">队列初始化:</span> 使用LinkedList实现Queue接口</li>
                    <li><span class="font-medium">层级处理:</span> 通过levelSize记录每层节点数，确保正确处理每层</li>
                    <li><span class="font-medium">子节点处理:</span> 左右子节点不为空时才加入队列</li>
                    <li><span class="font-medium">结果存储:</span> 每层处理完成后，将结果存入最终列表</li>
                </ul>
            </div>
        </section>
    </main>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true
            }
        });
    </script>
</body>
</html>
```